#ifndef TITLEBAR_H
#define TITLEBAR_H

#define KYLIN_USER_GUIDE_PATH "/"
#define KYLIN_USER_GUIDE_SERVICE "com.kylinUserGuide.hotel"
#define KYLIN_USER_GUIDE_INTERFACE "com.guide.hotel"

#include <QWidget>
#include <QToolButton>
#include <QPushButton>
#include <QMenu>
#include <QLabel>
#include <QList>
#include <QAction>
#include <QPalette>
#include <kysdk/applications/ksearchlineedit.h>
#include <unistd.h>

#include "searchserver.h"
#include "fileinfo.h"
#include "publicattributes.hpp"

class Titlebar : public QWidget
{
    Q_OBJECT
public:
    Titlebar(QWidget *parent = nullptr);
    ~Titlebar();
    void hideButton();
    void hideSearchLine();
    void initHelp(); // 设置帮助Action
    void setTheme(PublicAttributes::Theme theme);
    void setBackground(bool isDefault = true);

Q_SIGNALS:
    void sigAboutWinShow();
    void sigSearchResult(const QMap<QString, FileInfo> &searchResult);
    void sigSearchLineShow();
    void sigSearchInitFail();
    void sigStartSearch();

public Q_SLOTS:
    void onClicked(void);
    void triggerMenu(QAction *);
    void onSearchInstalled(bool isUpdated, QString searchInfoPath);
    void onBackButtonClick();

private Q_SLOTS:
    void onTextChanged();
    void onReturnPressed();

private:
    void initUI();
    void connectInit(void); // 绑定槽函数
    void initMenu(void);    // 设置菜单
    void initAbout();       // 设置关于Action

private:
    QPushButton *m_titleIcon = nullptr;
    QLabel *m_titleNameLab = nullptr;
    kdk::KSearchLineEdit *m_searchLine = nullptr;
    QToolButton *m_menuBtn = nullptr;                                 // 菜单按钮
    QMenu *m_menu = nullptr;                                          // 菜单
    QList<QAction *> m_actions;                                       // action组
    QPushButton *m_minBtn = nullptr;                                  // 最小化按钮
    QPushButton *m_maxBtn;                                            // 最大化按钮
    QPushButton *m_closeBtn = nullptr;                                // 关闭按钮
    PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 主题
    bool m_isDefault = true;

    SearchServer *m_searchServer = nullptr;
    QString m_query = "";
    QMap<QString, FileInfo> m_resultMap;
    QMutex m_mutex;
};

#endif // TITLEBAR_H
